﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;

namespace ajax
{
    public partial class process : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "text/xml";
            string type = Request.QueryString["type"];

            switch (type)
            {
                case "add":
                    chatengine.AddMes(Request.QueryString["user"], Request.QueryString["mes"]);
                    break;
                case "get":
                  List<XElement> chats= chatengine.GetChats(Convert.ToInt32(Request.QueryString["id"]));
                  Response.Write("<chats>");
                  foreach (XElement x in chats)
                  {
                      Response.Write(x.ToString());
                     // Response.Write(x.Element("user").Value + ":" + x.Element("mes").Value + "</br>");
                  }
                  Response.Write("</chats>");
                    break;
                case "last":
                   Response.Write(chatengine.GetLastMesID());
                    break;
                default:
                    break;
            }
          
        }
    }
}